package cjm.task5.config;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component("myAuthenticationFailHandler")
public class MyAuthenticationFailHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        //System.out.println("myAuthenticationFailHandler");
        String userid = httpServletRequest.getParameter("userid");
        String userPassword = httpServletRequest.getParameter("userPassword");
        String uri = "/doLogin?userid=" + userid + "&userPassword=" + userPassword;
        httpServletResponse.sendRedirect(uri);
    }
}
